package baidu.thread;

public class TestThread {
	
	private static int count;
	
	public synchronized void add(){
		count++;
		System.out.println(Thread.currentThread().getName()+"Add one: "+count);
	}
	
	public synchronized void sub(){
		count--;
		System.out.println("Sub one: "+count);
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		TestThread test = new TestThread();
		Runnable addThread = new AddThread(test);
		Thread addThread1 = new Thread(addThread);
		addThread1.setName("addThread1");
		Thread addThread2 = new Thread(addThread);
		addThread2.setName("addThread2");
		addThread1.start();
		addThread2.start();
		
		SubThread subThread = new SubThread(test);
		Thread subThread1 = new Thread(subThread);
		Thread subThread2 = new Thread(subThread);
		subThread1.start();
		subThread2.start();
		

	}
	


}
